import http from '@/api'

const authUrl = `${import.meta.env.VITE_APP_API_AUTH_URL}/auth`

// 获取验证码
const getVerifyCode = <T = any>() => {
  return http.get<T>(`${authUrl}/getPicCode`)
}

// 登录
const setLogin = <T = any>(params: ApiAuth.ReqLogin) => {
  return http.post<T>(`${authUrl}/login`, params)
}

// 登出
const setLogout = () => {
  return http.post(`${authUrl}/logout`)
}

// 修改密码
const setPasswordChange = (params: any) => {
  return http.put(`${authUrl}/pwd`, params)
}
// 获取用户信息
const getUserInfo = <T = any>() => {
  return http.post<T>(`${authUrl}/info`)
}
// 获取公钥
const getPubKey = () => {
  return http.get(`${authUrl}/pubKey`)
}

const AuthService = {
  getVerifyCode: getVerifyCode,
  setLogin: setLogin,
  setLogout: setLogout,
  getUserInfo: getUserInfo,
  setPasswordChange: setPasswordChange,
  getPubKey: getPubKey
}

export default AuthService
